package org.csu.gp_store.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.csu.gp_store.bo.*;
import org.csu.gp_store.common.*;
import org.csu.gp_store.entity.*;
import org.csu.gp_store.service.*;
import org.csu.gp_store.util.MD5Util;
import org.csu.gp_store.util.SentMailUtil;
import org.csu.gp_store.util.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.mail.MessagingException;

import java.util.ArrayList;
import java.util.List;

import static org.csu.gp_store.common.EmailCodeList.*;

@RestController
@RequestMapping("/company")
public class CompanyController {


    @Autowired
    CompanyService companyService;

    @Autowired
    FactoryService factoryService;

    @Autowired
    FacBusinessService facBusinessService;

    @Autowired
    ProductService productService;

    @Autowired
    ItemService itemService;

    @Autowired
    OrderService orderService;

    @Autowired
    OrderItemService orderItemService;

    /**
     * 公司登录
     * @param company 公司账号的邮箱和密码
     * @return 公司ID的token
     */
    @PostMapping("/login")
    public CommonResponse<String> companyLogin(@RequestBody Company company){
        if(company.getEmail()==null||company.getPassword()==null){
            return CommonResponse.createForError("邮箱或密码不能为空！");
        }
        String token = companyService.companyLogin(company.getEmail(),company.getPassword());
        return CommonResponse.createForSuccess(token,"登陆成功");
    }

    /**
     * 公司账户注册
     * @param company 公司信息
     * @param verifyCode 发送的验证码
     * @return 是否成功
     */
    @PostMapping("/register")
    public CommonResponse<String> register(@RequestBody Company company, @RequestParam("code") String verifyCode) {
        // 空判断
        if (null == verifyCode || "".equals(verifyCode)) {
            return CommonResponse.createForError("验证码不能为空");
        }
        // 先验证验证码是否正确
        String trueCode = EmailCodeList.getCode(company.getEmail(), COMPANY_ACCOUNT_REGISTER);
        // 验证码过期 或者根本没发给经销商验证码
        if (null == trueCode) {
            return CommonResponse.createForError("请重试发送验证码");
        }
        System.out.println("verifyCode:" + verifyCode);
        System.out.println("trueCode" + trueCode);
        // 判断验证码是否正确
        if (!trueCode.equals(verifyCode)) {
            return CommonResponse.createForError("验证码错误，请重新输入！");
        }

        // 判断邮箱,公司名是否存在
        if (companyService.emailExist(company.getEmail())) {
            return CommonResponse.createForError("邮箱" + company.getEmail() + "已存在");
        }
        if (companyService.nameExist(company.getCompanyName())) {
            return CommonResponse.createForError("商家名" + company.getCompanyName() + "已存在");
        }
        company.setPassword(MD5Util.getMD5String(company.getPassword()));
        if (companyService.insertNewCompany(company) == 1) {
            return CommonResponse.createForSuccessMsg("注册成功");
        }
        return CommonResponse.createForError("服务器错误，创建账号异常，请重试");
    }

    /**
     * 发送公司注册的验证码
     * @param email 需要注册的邮箱
     * @return 发送是否成功
     */
    @PostMapping("/register/verifyCode")
    public CommonResponse<String> sendVerifyCodeForRegister(@RequestParam("email") String email) {
        System.out.println("email: " + email);
        if (companyService.emailExist(email)) {
            return CommonResponse.createForError("邮箱已被注册，请更换后重试");
        }
        String verifyCode = RandomCode.getRandomCode();
        String msg = "您的验证码为:" + verifyCode + "，如果您未进行过这样的操作请无视该信息。";
        try {
            new SentMailUtil().sentSimpleMail("好搭档微商城-经销商注册验证码", msg, email);
            addCode(email, verifyCode, COMPANY_ACCOUNT_REGISTER);
        } catch (MessagingException e) {
            e.printStackTrace();
            return CommonResponse.createForSuccessMsg("验证码发送失败");
        }
        return CommonResponse.createForSuccessMsg("验证码已发送至您的邮箱");
    }

    /**
     * 修改公司信息
     * @param company 修改后的公司信息
     * @param MyToken 登录后给的token
     * @return 修改是否成功
     */
    @PostMapping("/info")
    public CommonResponse<String> changeInfo(@RequestBody Company company,@RequestHeader("MyToken") String MyToken){
        if(MyToken == null || ("").equals(MyToken)){
            return CommonResponse.createForError("请登录后再进行该操作");
        }
        String verifyToken = TokenUtil.getUserIdByToken(MyToken);
        if(verifyToken==null){
            return CommonResponse.createForError("身份校验失败，请重新登陆");
        }
        Long companyID = Long.valueOf(verifyToken);
        company.setCompanyID(companyID);
        if(companyService.alterCompanyInfo(company)==0){
            return CommonResponse.createForError("修改失败，请稍后重试");
        }
        return CommonResponse.createForSuccessMsg("修改成功");
    }

    /**
     * 获取公司信息
     * @param MyToken 登录后获取的token
     * @return 公司信息
     */
    @GetMapping("/info")
    public CommonResponse<Company> getInfo(@RequestHeader("MyToken") String MyToken){
        if(MyToken == null || ("").equals(MyToken)){
            return CommonResponse.createForError("请登录后再进行该操作");
        }
        String verifyToken = TokenUtil.getUserIdByToken(MyToken);
        if(verifyToken==null){
            return CommonResponse.createForError("身份校验失败，请重新登陆");
        }
        Long companyID = Long.valueOf(verifyToken);
        return CommonResponse.createForSuccess(companyService.getCompany(companyID));
    }

    /**
     * 添加公司商品（product）
     * @param MyToken 登陆后获取的token
     * @param factoryBO 工厂业务对象，就是factory和product的集合 传入product对象和factoryID即可
     * @return 是否添加成功
     */
    @PostMapping("/business/product/new")
    public CommonResponse<String> addCompanyProduct(@RequestHeader("MyToken") String MyToken,@RequestBody FactoryBO factoryBO){
        if(MyToken == null || ("").equals(MyToken)){
            return CommonResponse.createForError("请登录后再进行该操作");
        }
        String verifyToken = TokenUtil.getUserIdByToken(MyToken);
        if(verifyToken==null){
            return CommonResponse.createForError("身份校验失败，请重新登陆");
        }
        Long companyID = Long.valueOf(verifyToken);
        factoryBO.setCompanyID(companyID);
        if(productService.insertProduct(FactoryBO.toProduct(factoryBO))==0){
            return CommonResponse.createForError("添加失败,商品已存在");
        }
//        if(productService.getProductID(companyID,factoryBO.getProductName())!=null) {
//            factoryBO.setProductID(productService.getProductID(companyID, factoryBO.getProductName()));
//        }else {
//            return CommonResponse.createForError("添加失败");
//        }
//        if(facBusinessService.addFactoryBusiness(factoryBO)==0){
//            return CommonResponse.createForError("添加失败,商品已存在");
//        }
        return CommonResponse.createForSuccessMsg("添加成功");
    }

    /**
     * 将商品和生产工厂绑定
     * @param MyToken
     * @param facBusiness 传入productID和factoryID
     * @return 是否成功
     */
    @PostMapping("/business/new")
    public CommonResponse<String> addCompanyBusiness(@RequestHeader("MyToken") String MyToken,@RequestBody FacBusiness facBusiness){
        if(MyToken == null || ("").equals(MyToken)){
            return CommonResponse.createForError("请登录后再进行该操作");
        }
        String verifyToken = TokenUtil.getUserIdByToken(MyToken);
        if(verifyToken==null){
            return CommonResponse.createForError("身份校验失败，请重新登陆");
        }
        if(facBusinessService.addFactoryBusiness(facBusiness)==0){
            return CommonResponse.createForError("添加失败,商品已存在");
        }
        return CommonResponse.createForSuccessMsg("添加成功");
    }

    /**
     * 获取公司下的商品
     * @param MyToken 登陆后获取的token
     * @return 公司的所有product（List）
     */
    @GetMapping("/business/product")
    public CommonResponse<List<Product>> getCompanyBusiness(@RequestHeader("MyToken") String MyToken){
        if(MyToken == null || ("").equals(MyToken)){
            return CommonResponse.createForError("请登录后再进行该操作");
        }
        String verifyToken = TokenUtil.getUserIdByToken(MyToken);
        if(verifyToken==null){
            return CommonResponse.createForError("身份校验失败，请重新登陆");
        }
        Long companyID = Long.valueOf(verifyToken);
        List<Product> productList = facBusinessService.getAllBusiness(companyID);
        for(Product product:productList){
            product.setStatusDes(ProductStatusCode.getDescriptionByCode(product.getStatus()));
            if(facBusinessService.selectFactoryID(product.getProductID(),companyID).size()>0) {
                product.setFactoryList(facBusinessService.selectFactoryID(product.getProductID(), companyID));
            }else {
                product.setFactoryList(null);
            }
        }
        return CommonResponse.createForSuccess(productList);
    }

    /**
     * 修改product相关信息
     * @param ProductID productID
     * @param factoryBO 工厂业务对象，就是factory和product的集合，只传入product即可
     * @param MyToken 登录后获取的token
     * @return 是否修改成功
     */
    @PostMapping("/business/{ProductID}")
    public CommonResponse<String> changeBusiness(@PathVariable Long ProductID,
                                                  @RequestBody FactoryBO factoryBO,
                                                  @RequestHeader("MyToken") String MyToken){
        if(MyToken == null || ("").equals(MyToken)){
            return CommonResponse.createForError("请登录后再进行该操作");
        }
        if(factoryBO.getStatus()==3){
            return CommonResponse.createForError("不可以将状态设置为3");
        }
        String verifyToken = TokenUtil.getUserIdByToken(MyToken);
        if(verifyToken==null){
            return CommonResponse.createForError("身份校验失败，请重新登陆");
        }
        if(productService.updateProductDescription(ProductID,factoryBO.getDescription())==0){
            return CommonResponse.createForError("修改失败");
        }
        if(productService.updateProductName(ProductID,factoryBO.getProductName())==0){
            return CommonResponse.createForError("修改失败");
        }
        if(productService.updateProductStatus(ProductID,factoryBO.getStatus()+"")==0){
            return CommonResponse.createForError("修改失败");
        }
        return CommonResponse.createForSuccessMsg("修改成功");
    }

    /**
     * 获取公司某一product的所有item
     * @param ProductID 字面意思
     * @param MyToken 公司登录后获取的token
     * @return itemList
     */
    @GetMapping("/business/{ProductID}/item")
    public CommonResponse<List<Item>> getAllItem(@PathVariable Long ProductID,
                                                 @RequestHeader("MyToken") String MyToken){
        if(MyToken == null || ("").equals(MyToken)){
            return CommonResponse.createForError("请登录后再进行该操作");
        }
        String verifyToken = TokenUtil.getUserIdByToken(MyToken);
        if(verifyToken==null){
            return CommonResponse.createForError("身份校验失败，请重新登陆");
        }
        Long companyID = Long.valueOf(verifyToken);
        List<Item> itemList = itemService.getItemListByProductID(ProductID);
        return CommonResponse.createForSuccess(itemList);
    }

    /**
     * 添加product下的商品
     * @param ProductID productID
     * @param itemBO item业务对象，product和item二合一,传入的时候填入item信息
     * @param MyToken 公司登录后获取的token
     * @return 是否添加成功
     */
    @PostMapping("/business/{ProductID}/item/new")
    public CommonResponse<String> addItem(@PathVariable Long ProductID,
                                          @RequestBody ItemBO itemBO,
                                          @RequestHeader("MyToken") String MyToken){
        if(MyToken == null || ("").equals(MyToken)){
            return CommonResponse.createForError("请登录后再进行该操作");
        }
        String verifyToken = TokenUtil.getUserIdByToken(MyToken);
        if(verifyToken==null){
            return CommonResponse.createForError("身份校验失败，请重新登陆");
        }
        Long companyID = Long.valueOf(verifyToken);
        itemBO.setCompanyID(String.valueOf(companyID));
        itemBO.setProductID(String.valueOf(ProductID));
        if(itemService.insertItem(ItemBO.ItemBOToItem(itemBO))==0){
            return CommonResponse.createForError("添加失败，请检查信息");
        }
        return CommonResponse.createForSuccessMsg("添加成功");
    }

    /**
     * 删除某一商品
     * @param ProductID productId
     * @param MyToken token
     * @return 是否成功
     */
    @PostMapping("/business/{ProductID}/delete")
    public CommonResponse<String> deleteProduct(@PathVariable Long ProductID,
                                                @RequestHeader("MyToken") String MyToken){
        if(MyToken == null || ("").equals(MyToken)){
            return CommonResponse.createForError("请登录后再进行该操作");
        }
        String verifyToken = TokenUtil.getUserIdByToken(MyToken);
        if(verifyToken==null){
            return CommonResponse.createForError("身份校验失败，请重新登陆");
        }
        List<Item> itemList = itemService.getItemListByProductID(ProductID);
        if(itemList.size()>0) {
            for (Item item : itemList) {
                itemService.updateItemStatus(item.getItemID(),3);
            }
        }
        if(productService.updateProductStatus(ProductID,"3")==0){
            return CommonResponse.createForError("删除失败");
        }
        return CommonResponse.createForSuccess("删除成功");
    }

    @PostMapping("/business/{ProductID}/{itemID}")
    public CommonResponse<String> deleteItem(@PathVariable Long itemID,
                                             @RequestHeader("MyToken") String MyToken){
        if(MyToken == null || ("").equals(MyToken)){
            return CommonResponse.createForError("请登录后再进行该操作");
        }
        String verifyToken = TokenUtil.getUserIdByToken(MyToken);
        if(verifyToken==null){
            return CommonResponse.createForError("身份校验失败，请重新登陆");
        }
        if(itemService.updateItemStatus(itemID,3)==0){
            return CommonResponse.createForError("删除失败");
        }
        return CommonResponse.createForSuccess("删除成功");
    }

    /**
     * 获取公司下的所有工厂
     * @param MyToken 登陆后获取的token
     * @return factoryList
     */
    @GetMapping("/factory")
    public CommonResponse<List<Factory>> getFactories(@RequestHeader("MyToken") String MyToken){
        if(MyToken == null || ("").equals(MyToken)){
            return CommonResponse.createForError("请登录后再进行该操作");
        }
        String verifyToken = TokenUtil.getUserIdByToken(MyToken);
        if(verifyToken==null){
            return CommonResponse.createForError("身份校验失败，请重新登陆");
        }
        Long companyID = Long.valueOf(verifyToken);
        List<Factory> factories = factoryService.getFactoryList(companyID);
        if(factories==null){
            return CommonResponse.createForError("公司不存在，请重试");
        }
        List<Factory> factoriesReturn = new ArrayList<>();
        for(Factory factory:factories){
            factory.setStatusDes(FactoryStatus.getDescription(factory.getStatus()));
            factoriesReturn.add(factory);
        }
        return CommonResponse.createForSuccess(factoriesReturn);
    }

    /**
     * 添加新的factory
     * @param MyToken 登录后获取的token
     * @param factoryBO 要添加的工厂对象 只用传入factory，其中不用id
     * @return 是否添加成功
     */
    @PostMapping("/factory/new")
    public CommonResponse<String> newFactory(@RequestHeader("MyToken") String MyToken,
                                              @RequestBody FactoryBO factoryBO){
        if(MyToken == null || ("").equals(MyToken)){
            return CommonResponse.createForError("请登录后再进行该操作");
        }
        String verifyToken = TokenUtil.getUserIdByToken(MyToken);
        if(verifyToken==null){
            return CommonResponse.createForError("身份校验失败，请重新登陆");
        }
        Long companyID = Long.valueOf(verifyToken);
        factoryBO.setCompanyID(companyID);
        factoryBO.setStatus(0);
        Factory factory = FactoryBO.toFactory(factoryBO);
        if(factoryService.insertFactory(factory)==0){
            return CommonResponse.createForError("添加失败，请稍后重试");
        }
        return CommonResponse.createForSuccessMsg("添加成功");
    }

    /**
     * 修改相关工厂信息
     * @param factoryID 工厂ID
     * @param factoryBO 修改后的工厂对象,包括对状态的修改
     * @param MyToken 登陆后获取的token
     * @return 是否成功
     */
    @PostMapping("/factory/{factoryID}")
    public CommonResponse<String> manageFactory(@PathVariable Long factoryID,
                                                @RequestBody FactoryBO factoryBO,
                                                @RequestHeader("MyToken") String MyToken){
        if(MyToken == null || ("").equals(MyToken)){
            return CommonResponse.createForError("请登录后再进行该操作");
        }
        String verifyToken = TokenUtil.getUserIdByToken(MyToken);
        if(verifyToken==null){
            return CommonResponse.createForError("身份校验失败，请重新登陆");
        }
        Long companyID = Long.valueOf(verifyToken);
        factoryBO.setFactoryID(factoryID);
        factoryBO.setCompanyID(companyID);
        if(factoryService.changeFactory(FactoryBO.toFactory(factoryBO))==0){
            return CommonResponse.createForError("修改失败");
        }
        return CommonResponse.createForSuccessMsg("修改成功");
    }

    /**
     * 获取某一工厂可生产的所有商品
     * @param factoryID 工厂ID
     * @param MyToken 登陆后获取的token
     * @return 返回工厂的所有商品list
     */
    @GetMapping("/factory/{factoryID}")
    public CommonResponse<List<FactoryBO>> getCertainFactoryBusiness(@PathVariable Long factoryID,
                                                       @RequestHeader("MyToken") String MyToken){
        if(MyToken == null || ("").equals(MyToken)){
            return CommonResponse.createForError("请登录后再进行该操作");
        }
        String verifyToken = TokenUtil.getUserIdByToken(MyToken);
        if(verifyToken==null){
            return CommonResponse.createForError("身份校验失败，请重新登陆");
        }
        List<FactoryBO> factoryBOList = new ArrayList<>();
        Factory factory = factoryService.getCertainFactory(factoryID);
        List<FacBusiness> facBusinessList = facBusinessService.getFacBusiness(factoryID);
        if(facBusinessList.size()>0) {
            for (FacBusiness facBusiness : facBusinessList) {
                ProductBO product = productService.getProductByProductID(facBusiness.getProductID());
                FactoryBO factoryBO = FactoryBO.toFactoryBO(factory, product);
                factoryBOList.add(factoryBO);
            }
        }
        return CommonResponse.createForSuccess(factoryBOList);
    }

    /**
     * 获取某一工厂信息
     * @param factoryID 工厂ID
     * @param MyToken 公司登录后获取的token
     * @return Factory对象
     */
    @GetMapping("/factory/{factoryID}/info")
    public CommonResponse<Factory> getCertainFactoryInfo(@PathVariable Long factoryID,
                                                             @RequestHeader("MyToken") String MyToken){
        if(MyToken == null || ("").equals(MyToken)){
            return CommonResponse.createForError("请登录后再进行该操作");
        }
        String verifyToken = TokenUtil.getUserIdByToken(MyToken);
        if(verifyToken==null){
            return CommonResponse.createForError("身份校验失败，请重新登陆");
        }
        Factory factory = factoryService.getCertainFactory(factoryID);
        if(factory!=null) {
            return CommonResponse.createForSuccess(factory);
        }
        return CommonResponse.createForError("未查找到相应的工厂信息，请稍后重试");
    }

    /**
     * 获取公司的所有订单
     * @param MyToken 根据登录获取的token
     * @return 所有订单
     */
    @GetMapping("/orders")
    public CommonResponse<List<OrdersBO>> getCompanyOrders(@RequestHeader("MyToken") String MyToken){
        if(MyToken == null || ("").equals(MyToken)){
            return CommonResponse.createForError("请登录后再进行该操作");
        }
        String verifyToken = TokenUtil.getUserIdByToken(MyToken);
        if(verifyToken==null){
            return CommonResponse.createForError("身份校验失败，请重新登陆");
        }
        Long companyID = Long.valueOf(verifyToken);
        List<OrderItem> orderItemList = companyService.getOrdersByCompanyID(companyID);
        System.out.println(orderItemList);
        List<OrdersBO> ordersBOList = new ArrayList<>();
        if(orderItemList.size()>0) {
            for (OrderItem orderItem : orderItemList) {
                Orders orders = orderService.getOrderByOrderID(orderItem.getOrderID());
                if(orders==null){
                    return CommonResponse.createForError("未查到找订单信息，请重试");
                }
                OrdersBO ordersBO = OrdersBO.toOrdersBO(orders, orderItem);
                ordersBOList.add(ordersBO);
            }
        }
        return CommonResponse.createForSuccess(ordersBOList);
    }

    /**
     * 获取一个相应的订单下的所有商品
     * @param MyToken token
     * @param orderID orderID
     * @return 公司某个订单负责的所有商品
     */
    @GetMapping("/orders/{orderID}")
    public CommonResponse<List<OrderItem>> getCertainOrder(@RequestHeader("MyToken") String MyToken,
                                                     @PathVariable Long orderID){
        if(MyToken == null || ("").equals(MyToken)){
            return CommonResponse.createForError("请登录后再进行该操作");
        }
        String verifyToken = TokenUtil.getUserIdByToken(MyToken);
        if(verifyToken==null){
            return CommonResponse.createForError("身份校验失败，请重新登陆");
        }
        Long companyID = Long.valueOf(verifyToken);
        List<OrderItem> orderItemList = companyService.getCertainOrder(companyID,orderID);
        return CommonResponse.createForSuccess(orderItemList);
    }

    /**
     * 修改某个订单商品的信息，比如物流之类的
     * @param indexID 行号
     * @param MyToken token
     * @param orderItem 修改之后的orderitem
     * @return 是否成功
     */
    @PostMapping("/orders/{orderID}/{indexID}")
    public CommonResponse<String> manageOrder(@PathVariable Long indexID,
                                              @RequestHeader("MyToken") String MyToken,
                                              @RequestBody OrderItem orderItem){
        if(MyToken == null || ("").equals(MyToken)){
            return CommonResponse.createForError("请登录后再进行该操作");
        }
        String verifyToken = TokenUtil.getUserIdByToken(MyToken);
        if(verifyToken==null){
            return CommonResponse.createForError("身份校验失败，请重新登陆");
        }
        Long companyID = Long.valueOf(verifyToken);
        orderItem.setIndexID(indexID);
        orderItem.setCompanyID(companyID);
        if(orderItemService.manageOrder(orderItem)==0){
            return CommonResponse.createForError("操作失败，请稍后重试");
        }
        Long factoryID = orderItem.getFactoryID();
        if(factoryID!=null){
            Factory factory = factoryService.getCertainFactory(factoryID);
            factory.setStatus(1);
            factoryService.changeFactory(factory);
        }
        return CommonResponse.createForSuccess("操作成功");
    }

    /**
     * 接受某一订单商品
     * @param indexID 行号
     * @param MyToken token
     * @return 是否成功
     */
    @PostMapping("/orders/{orderID}/{indexID}/accept")
    public CommonResponse<String> acceptOrder(@PathVariable Long indexID,
                                              @RequestHeader("MyToken") String MyToken){
        if(MyToken == null || ("").equals(MyToken)){
            return CommonResponse.createForError("请登录后再进行该操作");
        }
        String verifyToken = TokenUtil.getUserIdByToken(MyToken);
        if(verifyToken==null){
            return CommonResponse.createForError("身份校验失败，请重新登陆");
        }
        if(companyService.dealOrder(indexID,1)==0){
            return CommonResponse.createForError("接受订单失败，请稍后重试");
        }
        return CommonResponse.createForSuccess("接受订单成功");
    }

    /**
     * 拒绝某一订单商品
     * @param indexID 行号
     * @param MyToken token
     * @return 是否成功
     */
    @PostMapping("/orders/{orderID}/{indexID}/deny")
    public CommonResponse<String> denyOrder(@PathVariable Long indexID,
                                            @RequestHeader("MyToken") String MyToken){
        if(MyToken == null || ("").equals(MyToken)){
            return CommonResponse.createForError("请登录后再进行该操作");
        }
        String verifyToken = TokenUtil.getUserIdByToken(MyToken);
        if(verifyToken==null){
            return CommonResponse.createForError("身份校验失败，请重新登陆");
        }
        if(companyService.dealOrder(indexID,7)==0){
            return CommonResponse.createForError("拒绝订单失败，请稍后重试");
        }
        return CommonResponse.createForSuccess("已拒绝订单");
    }

    @GetMapping("/orders/{indexID}/factory")
    public CommonResponse<List<Long>> getFactorybyOrder(@PathVariable Long indexID,
                                                        @RequestHeader("MyToken") String MyToken){
        if(MyToken == null || ("").equals(MyToken)){
            return CommonResponse.createForError("请登录后再进行该操作");
        }
        String verifyToken = TokenUtil.getUserIdByToken(MyToken);
        if(verifyToken==null){
            return CommonResponse.createForError("身份校验失败，请重新登陆");
        }
        OrderItem orderItem = orderItemService.getOrderItemByIndexID(indexID);
        if(orderItem.getProductID()!=null) {
            return CommonResponse.createForSuccess(facBusinessService.getAllFactoryByProductID(orderItem.getProductID()));
        }
        return CommonResponse.createForSuccess(new ArrayList<>());
    }

    /**
     * 不太用得上的方法
     * @param orderID orderID
     * @param MyToken token
     * @return 是否成功
     */
    @PostMapping("/orders/{orderID}/forceDeny")
    public CommonResponse<String> forceDeny(@PathVariable Long orderID,
                                            @RequestHeader("MyToken") String MyToken){
        return null;
    }
}
